<template>
  <div class="formSelect">
    <el-select v-model="value" :multiple='!comData.node.isRadio' :placeholder="placeholder" filterable clearable
      @change='handleChange' @clear='clear' @remove-tag='clear'>
      <el-option v-for="item in comData.node.options" :key="item.value" :label="item.label" :value="item.value">
      </el-option>
    </el-select>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        value: '',
      }
    },
    props: {
      label: [String, Number],
      placeholder: {
        type: String,
        default: ''
      },
      comData: {
        type: Object,
        default: () => ({})
      }
    },
    mounted() {
      this.value = this.comData.node.default
      this.handleChange(this.value)
    },
    methods: {
      common(val){
        let obj = {}
        obj[this.label] = val
        this.$emit('setFormData', obj)
      },
      handleChange(val) {
        this.common(val)
      },
      clear(){
        this.common(this.value)
      }
    }
  }
</script>